package com.bit.cfdi.web.dao.impl;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.bit.cfdi.web.dao.TiempoDAO;
import com.bit.cfdi.web.domain.Tiempo;

@Repository
public class TiempoDAOImpl extends HibernateDaoSupport implements TiempoDAO {

	@Autowired
	@Transactional public void init(final SessionFactory sessionFactory) {
		setSessionFactory(sessionFactory);
	}
	
	@Override
	@Transactional public void save(final Tiempo tiempo) {
		getHibernateTemplate().saveOrUpdate(tiempo);
	}

	@SuppressWarnings("unchecked")
	@Override
	@Transactional public Tiempo getTiempo() {
		List<Tiempo> toReturn = getHibernateTemplate().find(
				" from Tiempo as t");
		return toReturn.size()>0?toReturn.get(0):null;
	}

}
